﻿@{
    var gridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSize;
    
    //page title
    ViewBag.Title = T("Admin.Configuration.Settings.AllSettings").Text;
}
@using Telerik.Web.Mvc.UI;
@using System.Linq;
<div class="section-header">
    <div class="title">
        <img src="@Url.Content("~/Administration/Content/images/ico-configuration.png")" alt="" />
        @T("Admin.Configuration.Settings.AllSettings")
    </div>
</div>
<table class="adminContent">
    <tr>
        <td>
            @T("Admin.Configuration.Settings.AllSettings.Description")
        </td>
    </tr>
    <tr>
        <td>
            @(Html.Telerik().Grid<SettingModel>()
                    .Name("settings-grid")
                    .DataKeys(x =>
                    {
                        x.Add(y => y.Id).RouteKey("Id");
                    })
                    .Columns(columns =>
                    {
                        columns.Bound(x => x.Name);
                        columns.Bound(x => x.Value);
                        columns.Bound(x => x.Store).EditorTemplateName("Store");
                        columns.Command(commands =>
                        {
                            commands.Edit().Text(T("Admin.Common.Edit").Text);
                            commands.Delete().Text(T("Admin.Common.Delete").Text);
                        }).Width(200);

                    })
                    .ToolBar(x => x.Insert())
                    .Editable(x =>
                    {
                        x.Mode(GridEditMode.InLine);
                    })
                    .Filterable()
                    .Pageable(settings => settings.PageSize(gridPageSize).Position(GridPagerPosition.Both))
                    .DataBinding(dataBinding =>
                    {
                        dataBinding.Ajax().Select("AllSettings", "Setting")
                            .Update("SettingUpdate", "Setting")
                            .Delete("SettingDelete", "Setting")
                            .Insert("SettingAdd", "Setting");
                    })
                    .ClientEvents(x => x.OnError("grid_onError").OnEdit("grid_onStoreEdit"))
                    .EnableCustomBinding(true))
            <script type="text/javascript">
                function grid_onError(e) {
                    alert(e.XMLHttpRequest.responseText);
                    e.preventDefault();
                }
                
                function grid_onStoreEdit(e) {
                    $(e.form).find('#Store').data('tDropDownList').select(function (dataItem) {
                        return dataItem.Value == e.dataItem['StoreId'];
                    });
                }
            </script>
        </td>
    </tr>
</table>
